/*
* 选择车辆页面
* */

import 'package:center_beijing/api/product_api.dart';
import 'package:center_beijing/common/styles.dart';
import 'package:center_beijing/config/global_config.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

class SelectCar extends StatefulWidget {
  @override
  _SelectCarState createState() => _SelectCarState();
}

class _SelectCarState extends State<SelectCar>
    with SingleTickerProviderStateMixin {
  AnimationController _controller;
  List dataSource = [];

  @override
  void initState() {
    _controller = AnimationController(vsync: this);
    super.initState();
    this.getCarList();
  }

  @override
  void dispose() {
    _controller.dispose();
    super.dispose();
  }

  /*
  * 获取车辆列表
  * */
  getCarList()async{
    var pass = {
      'projectId':GlobalConfig.selectFactory.value
    };
    var result = await getAllCars(pass);
    if (result != null) {
      this.setState(() {
        dataSource = result;
      });
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('选择车辆'),
      ),
      body: Container(
        color: Styles.MainBackgroundColor,
        padding:
            EdgeInsets.fromLTRB(0, 0, 0, MediaQuery.of(context).padding.bottom),
        child: CustomScrollView(slivers: <Widget>[
          SliverList(
            delegate: SliverChildBuilderDelegate(
              (context, index) {
                return GestureDetector(
                  onTap: () {
                    Get.back(result: dataSource[index]);
                  },
                  child: Container(
                    color: Colors.white,
                    padding: EdgeInsets.fromLTRB(Styles.spacing16,
                        Styles.spacing8, Styles.spacing16, Styles.spacing8),
                    margin: EdgeInsets.fromLTRB(
                        0, Styles.spacing4, 0, Styles.spacing4),
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Text(
                          "${dataSource[index]['transportPerson']}  ${dataSource[index]['vehicleNum']}",
                          style: TextStyle(
                              color: Styles.DetailColor,
                              fontSize: Styles.NormalFont),
                        ),
                        Text(
                          '${dataSource[index]['mobilePhone']}',
                          style: TextStyle(
                              color: Styles.DetailColor,
                              fontSize: Styles.NormalFont),
                        ),
                      ],
                    ),
                  ),
                );
              },
              childCount: dataSource.length,
            ),
          ),
        ]),
      ),
    );
  }
}
